//
//  Scene.h
//  archer
//
//  Created by Wu Wang on 12-5-22.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#ifndef archer_Scene_h
#define archer_Scene_h

#include "cocos2d.h"

enum SceneLayer
{
	LAYER_BACK,
	LAYER_BACKOBJ,
	LAYER_MIDDLE,
	LAYER_MAIN,
	LAYER_MAX
};
const int ZORDER_GROUND  = 50;
const int ZORDER_PLAYER  = 40;
const int ZORDER_OBJECTS = 30;
const int ZORDER_BACK    = 20;

class CScene : public cocos2d::CCLayer
{
public:
	CScene()
		: m_mainScale(1.0)
		, m_bScale(true)
		, m_bMove(true)
		, m_bStep(true)
	{

	}
	float GetLeftMin()   {return m_tableLeftMin;}
	float GetRightMin()  {return m_tableRightMin;}
	float GetLeftMax()   {return m_tableLeftMax;}
	float GetRightMax()  {return m_tableRightMax;}
	float GetMainScale() {return m_mainScale;}
	int   GetLeftTableHeight()  {return m_leftTableHeight;}
	int   GetRightTableHeight() {return m_rightTableHeight;}
	cocos2d::CCLayer *GetMainLayer() {return m_pLayScene[LAYER_MAIN];}
	cocos2d::CCPoint  GetTouchInMain(cocos2d::CCTouch *pTouch);
	cocos2d::CCPoint  GetPosInMain(cocos2d::CCPoint pt);
	
	void SetScaleCenter(cocos2d::CCPoint pt) {m_ptScaleCenter = pt;}
	void SetTableDist(int leftHeight, int rightHeight) {m_leftTableHeightDist = leftHeight; m_rightTableHeightDist = rightHeight;}
	void SetOrginPos(cocos2d::CCPoint pt) {m_ptOrgin = pt;}
	void LocateCurOrgin();

	void InitSceneBase(const char *szGroundPath, float groundTileWidth, const char *szBackPath, float backTileWidth, const char *szTablePath);
	void MoveMainScene(float xAdd, float yAdd);
	void ScaleMainScene(float dist);
	void ScaleMainWithCenter(cocos2d::CCPoint ptCenter, float curScale, float scaleSpeed = 30);
	void SetMainScale(float distScale, float duration);
	void SetMainMoveTo(cocos2d::CCPoint ptDist, float duration);
	bool UpdateScale(cocos2d::ccTime dt);
	void FollowObject(cocos2d::CCPoint pt);
	bool Shake(float dt, float duration, int time);
	
	bool CalStep(float *org, float dist, float mdt);

	virtual void initScene() = 0;
	virtual void updateScene(cocos2d::ccTime dt);
	virtual bool moveTable(cocos2d::ccTime dt);
protected:
	cocos2d::CCLayer  *m_pLayScene[LAYER_MAX];
	// 场景
	cocos2d::CCSprite *m_pSprTable[2];
	float              m_tableLeftMin;
	float              m_tableLeftMax;
	float              m_tableRightMin;
	float              m_tableRightMax;
	int                m_leftTableHeight;
	int                m_rightTableHeight;
	int                m_leftTableHeightDist;
	int                m_rightTableHeightDist;
	float              m_tableSpace;

	cocos2d::CCPoint         m_ptOrgin;
	cocos2d::CCPoint         m_ptOrginDist;
	float                    m_mainScale;
	float                    m_mainScaleDist;

	cocos2d::CCPoint         m_ptScaleCenter;
	float m_scaleSpeed;

	bool m_bScale;
	bool m_bMove;
	bool m_bStep;

	cocos2d::CCNode   *m_pParent;
};

class CScene1 : public CScene
{
public:
	CScene1() {}
	void initScene();
	bool moveTable(cocos2d::ccTime dt);
	void updateScene(cocos2d::ccTime dt);
	LAYER_NODE_FUNC(CScene1);
protected:
	void UpdateClouds(cocos2d::ccTime dt);
private:
	cocos2d::CCSprite *m_pSprCloud[6];
	cocos2d::CCSprite *m_pSprWheel[2];
};

class CScene2 : public CScene
{
public:
	CScene2() {}
	void initScene();
	LAYER_NODE_FUNC(CScene2);
};
class CSceneManager
{
public:
	static CScene *CreateScene(int id);
};

#endif
